package com.example.springboot_study.controller;

import com.example.springboot_study.common.exception.MyException;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author : liqun
 * @createTime : 2021/8/30 17:28
 */
@Controller
public class HellloController {
    @RequestMapping("/")
    public String index(ModelMap map) throws MyException{
        // 加入一个属性，用来在模板中读取
        map.addAttribute("host","http://blog.didispace.com");
        // return模板文件的名称，对应src/main/resources/templates/index.html
        return "index";

    }
    @RequestMapping("/hello")
    public String hello() throws Exception {
        throw new Exception("发生错误");
    }

    @RequestMapping("/json")
    public String json() throws MyException {
        throw new MyException("发生错误2");
    }
}
